using System;
using System.Security;
using BusinessLogic.Connectivity.Entities;

namespace Server.Container
{
	internal class ServerExceptionCatcher
	{
		public ServerResponse<T> Execute<T>(Func<ServerResponse<T>> func, T entity, string ticket) where T : class
		{
			try
			{
				return func();
			}
			catch (SecurityException e)
			{
				return new ServerResponse<T>(ServerResponseCode.Failure, e.Message, entity, ticket);
			}
			catch(Exception ex)
			{
				return new ServerResponse<T>(ServerResponseCode.Failure, ex.Message + " Please, try again or contact administrator.", entity, ticket);
			}
		}
	}
}